/// @tags: DPwithMonotoneQueue
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

int const M = 3e4 + 1;

int n, sum;
int s[M], d[M], w[M], q[M];

inline double slope(int j, int k) {
  return 1.0 * (d[j] * s[j] - d[k] * s[k]) / (s[j] - s[k]);
}

inline int count(int i, int j) { return sum - d[j] * s[j] - d[i] * (s[i] - s[j]); }

inline int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> w[i] >> d[i];
  for (int i = n; i >= 1; --i) d[i] += d[i + 1];
  for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + w[i], sum += d[i] * w[i];
  int l = 0, r = 0, ans = 0x3f3f3f3f;
  for (int i = 1; i <= n; ++i) {
    while (l < r && slope(q[l], q[l + 1]) > d[i]) ++l;
    ans = min(ans, count(i, q[l]));
    while (l < r && slope(q[r - 1], q[r]) < slope(q[r], i)) --r;
    q[++r] = i;
  }
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4360 [CEOI2004] 锯木厂选址.in", "r", stdin);
  freopen("P4360 [CEOI2004] 锯木厂选址.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
